# Maintainer: Jeff Hubbard <musikernel@gmail.com>

_realname=vamp-plugin-sdk
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.10.0
pkgrel=3
pkgdesc="Vamp plugins extract descriptive information from audio data (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://www.vamp-plugins.org/"
license=("BSD")
options=('!buildflags')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libsndfile")
source=("https://code.soundsoftware.ac.uk/attachments/download/2691/${_realname}-${pkgver}.tar.gz"
        "01-mingw-shared.patch"
        "02-clang.patch")
sha256sums=('aeaf3762a44b148cebb10cde82f577317ffc9df2720e5445c3df85f3739ff75f'
            'b3525265a6104403baadf2239a06a73da556eb894d956274d863bf6e434c8e83'
            '30a92217663b9a7755a1c9af5db7f00309f1d0dc4d3abb38712c46e8bbcb4c5c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/01-mingw-shared.patch

  if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
    patch -p1 -i ${srcdir}/02-clang.patch
  fi
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  cp -rf "${_realname}-${pkgver}" "build-${MINGW_CHOST}"
  cd build-${MINGW_CHOST}

  CFLAGS+=" -D_USE_MATH_DEFINES"
  CPPFLAGS+=" -D_USE_MATH_DEFINES"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make -j1
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
